package cc.yiueil.listener;

import lombok.extern.slf4j.Slf4j;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

@Slf4j
@WebListener
public class AppListener implements ServletContextListener {
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        // 应用初始化的操作, 可以在这里执行容器创建, 连接池等资源创建等
        log.debug("msg: {}", "contextInitialized");
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        // 上下文销毁的监听, 可以用于资源释放
        log.debug("msg: {}", "contextDestroyed");
        try {
            Thread.sleep(3000L);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}
